package com.sls.web.manager.action.recharge;

import javax.annotation.Resource;

import com.sls.web.manager.action.SuperAction;
import com.sls.web.manager.common.Constants;
import com.sls.web.manager.page.Pagination;
import com.sls.web.manager.recharge.pojo.SupplierTmp;
import com.sls.web.manager.recharge.querybean.SupplierTmpQuery;
import com.sls.web.manager.recharge.service.SupplierTmpService;

public class SupplierTmpAction extends SuperAction {
	private static final long serialVersionUID = -2649559109832001748L;
	@Resource(name = "supplierTmpService")
	private SupplierTmpService supplierTmpService;
	/**
	 * 返回分页对象
	 */
	public Pagination<?> page;
	private SupplierTmpQuery supplierTmpQuery;
	private SupplierTmp supplierTmp;
	private String id;
	private String property;
	private String keyword;

	public Pagination<?> getPage() {
		return page;
	}

	public void setPage(Pagination<?> page) {
		this.page = page;
	}

	public SupplierTmpQuery getSupplierTmpQuery() {
		return supplierTmpQuery;
	}

	public void setSupplierTmpQuery(SupplierTmpQuery supplierTmpQuery) {
		this.supplierTmpQuery = supplierTmpQuery;
	}

	public SupplierTmp getSupplierTmp() {
		return supplierTmp;
	}

	public void setSupplierTmp(SupplierTmp supplierTmp) {
		this.supplierTmp = supplierTmp;
	}

	public String getProperty() {
		return property;
	}

	public void setProperty(String property) {
		this.property = property;
	}

	public String getKeyword() {
		return keyword;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	// 列表
	public String list() {
		if (supplierTmpQuery == null) {
			supplierTmpQuery = new SupplierTmpQuery();
			supplierTmpQuery.setPageSize(Constants.INIT_PAGESIZE);
			supplierTmpQuery.setCurrentPage(Constants.INIT_CURRENTPAGE);
		}
		if ("name".equals(property)) {
			supplierTmpQuery.setName(keyword);
		}
		try {
			page = supplierTmpService.querySupplierTmp(supplierTmpQuery,
					getCurrentOperator());
		} catch (Exception e) {
			return ERROR;
		}

		return "list";
	}

	// 删除
	public String delete() throws Exception {
		if (id == null) {
			addActionError("请选择一条记录!");
			return this.list();
		} else {
			boolean result = supplierTmpService
					.delete(id, getCurrentOperator());
			if (!result) {
				addActionError("删除失败!");
				return this.list();
			} else {
				redirectionUrl = "supplier_tmp!list.htm";
				return "success";
			}
		}
	}

	// 同步更新供应商
	public String synchronous() throws Exception {
		boolean result = supplierTmpService.synchronous(id,
				getCurrentOperator());
		if (!result) {
			addActionError("同步失败!");
			return this.list();
		} else {
			redirectionUrl = "supplier_tmp!list.htm";
			return "success";
		}
	}
}